import {api} from './libs/api.js';
let _self;
export const index =  {
	data() {
		return {
			optLock:false,
			icons:{"50":uni.upx2px(50),"60":uni.upx2px(60),"40":uni.upx2px(40),"34":uni.upx2px(34)},
			rules:api.rules,
			formData:{"req_date":"","mark":"","products":[]},
			selectShow:false,
			params:{},
			product:{},
		}
	},
	
	
	watch:{
		product(val){
			for(let index in this.formData.products){
				if(this.formData.products[index]["cInvCode"]==val["cInvCode"]) return true;
			}
			this.formData.products.push(val);
		},
	},
	
	
	mounted() {
		_self = this;
	},
	onReachBottom:function(e){
		/*this.params.page+=1;
		this.initData();*/
	},
	onLoad:function(option) {
		//this.tabSubItem=option.status;
		this.params=option;
	},
	
	methods: {
		async initData(){
			//console.log(this.params);
			if(this.params["code"]){
				let productList = await api.u8ProductList( {"inv_code":this.params["code"],"is_sync":2,"page": 1,"pageSize": 20});
				if(productList&&productList.length>0) this.product=productList[0];
			}
		},
		
		delProduct(index){
			this.formData.products.splice(index,1);
		},
	
		selectPro(){
			this.selectShow=true;
		},
		
		async submitForm(){
			if(this.optLock) return true;
			this.optLock=true;
			let ret=await api.submitReGoods(this.formData);
			if(ret=="success"){
				uni.showToast({icon:"none",title:"提交成功！"});
				setTimeout(function(){uni.navigateTo({url: "/pages/regood/index?status=1"});},2000);　　
			}else{
				this.optLock=false;
			}
		}

		
				
	},
}